<template>
	<div class="nav">
		<el-page-header @back="goBack" content="登录">
		</el-page-header>
		<br />
		<el-form ref="form" :model="form" label-width="80px">
			<el-form-item label="用户名:">
				<el-input v-model="form.phone"></el-input>
			</el-form-item>
			<el-form-item label="密码:">
				<el-input v-model="form.pwd" type="password"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="onSubmit">立即登录</el-button>
				<el-button>取消</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	//引入axios
	import axios from 'axios'

	export default {
		name: 'Register',
		data() {
			return {
				form: {
					phone: '',
					pwd: '',
				}
			}
		},
		methods: {
			onSubmit() {
				//发起ajax请求
				axios({
					//请求地址
					url: 'http://localhost:8080/axios/login.do',
					//携带参数
					params:this.form,
					//请求方式
					method: 'post',
				}).then(
					res => {
						//登录成功
						if(res.data.msg === 'success'){
							//触发事件
							this.$bus.$emit('receiveParam',res.data.userPhone)
							this.$router.push({
								path: '/edu/about',
							})
						}
					},
					err => {
						console.log(err.message)
					}
				)

			},
			goBack() {
				this.$router.push({
					path:'/register'
				})
			}
		}
	}
</script>

<style scoped>
	.nav {
		width: 60%;
		margin: 0 auto
	}
</style>
